<?php
$eventpropertyStr = Yii::t('BWeSport', 'Event Property');
$detailcontentStr = Yii::t('BWeSport', 'Detail Content');
$eventtypeStr = Yii::t('BWeSport', 'Event Type');
$eventnameStr = Yii::t('BWeSport', 'Event Name');
$eventimageStr = Yii::t('BWeSport', 'Event Image');
$eventstarttimeStr = Yii::t('BWeSport', 'Event Start Time');
$eventendtimeStr = Yii::t('BWeSport', 'Event End Time');
$eventprofileStr = Yii::t('BWeSport', 'Event Profile');
$starttimeStr = Yii::t('BWeSport', 'Start Time');
$endtimeStr = Yii::t('BWeSport', 'End Time');
?>
<?php
$model = new BDynamicFormModel();
$modelClass = get_class($model);
$screen = Blyn::app()->getUIManager()->getCurrentScreen();
$url = $control->getLinkUrl(array('name' => '保存','id' => 'savejqEvent'), array(
    'eventId' => $eventId,
    'postModel' => $modelClass));
$updateId = $control->getAjaxContainerId();
?>
<?php
$eventTypeField = 'eventType_eventTypeId';
$eventNameField = 'event_name';
$eventDescriptionField = 'event_description';
$model->addField($eventNameField);
$model->addField($eventDescriptionField);
$model->addField($eventTypeField);

if ($eventId > 0) {
    $event = new BWEvent($eventId);
    $eventType = $event->getType();
    if ($eventType)
        $model->$eventTypeField = $eventType->getId();
    $model->$eventNameField = $event->name;
    $model->$eventDescriptionField = $event->description;
}
?>
<?php
$app = Blyn::app()->getActiveApp();
$typeList = $app->getEventTypeList('FullName');
$list = array('0' => '请选择');
$typeList = $list + $typeList;
?>
<style>
.ui-block-a, 
.ui-block-b, 
.ui-block-c 
{
background-color: lightgray;
border: 1px solid black;
//height: 100px;
font-weight: bold;
text-align: center;
padding: 10px;
}
a {text-decoration: none !important;color:gray !important;font-weight: normal !important;}
.title_bar {text-align: center;border-bottom: 1px solid #dedede;background-color: #80C8EE;color:white !important;font-size: 16px;line-height: 33px;}
.item_title {color: rgb(138, 138, 236);}
.item {
    margin-top: 10px;
    //border: 1px solid #dedede; 
    padding: 0 5px; 
    font-weight: bold;
    //background-color: white;
    margin-bottom: 5px;}
.btn_left {border:1px solid #dedede;float: left;font-size: 16px;width: 49%; height: 35px; background-color:rgb(242,242,242);text-align: center;color: gray;border-radius: 5px 0 0 5px;}
.btn_right {border:1px solid #dedede;float: left;font-size: 16px;width: 49%; height: 35px; background-color:rgb(242,242,242);text-align: center;color: gray;border-radius: 0 5px 5px 0;}
.input {background: none !important;}
</style>
<div data-role="header">
  <h1>旅游管理</h1>
  </div>
<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "addEventForm",
    //'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
?>
<script type="text/javascript">
// this script for collecting the form data and pass to the controller action and doing the on success validations
    function sendIt() {
//        var formData = new FormData($("#message-form")[0]);
        var formElement = document.getElementById("addEventForm");
        var formData = new FormData(formElement);
        $.ajax({
            url: '<?php echo $url; ?>',
            type: 'POST',
            data: formData,
            datatype: 'json',
            //datatype: 'html',
            // async: false,
            beforeSend: function() {
                //alert('url:');
                //alert('data:');
                $("#ajax-loaderdiv").show();
                //alert('1');
            },
            success: function(data) {
                // on success do some validation or refresh the content div to display the uploaded images 
                //alert(data);
                jQuery("#<?php echo $updateId; ?>").html(data);
            },
            complete: function() {
                //alert("3");
                $("#ajax-loaderdiv").hide();
            },
            error: function(jqXHR, textStatus, errorThrown) {
                //alert(textStatus);
                //alert(textStatus+';'+errorThrown);
                alert("There may a error on uploading. Try again later");
            },
            cache: false,
            contentType: false,
            processData: false
        });

        return false;
    }
</script>
<div data-role="content" class="ui-content" role="main" style="padding:0px;">
    <div class="item">
          <?php echo $eventnameStr; ?>
    </div>
        <?php
        echo $form->textField($model, $eventNameField, array('placeholder' => $eventnameStr . '...', 'required' => true));
        ?>
    <div class="item">
          <?php echo $eventtypeStr; ?>
    </div>
        <?php
        echo $form->dropDownList($model, $eventTypeField, $typeList, array('class' => 'span7'));
        ?>
    <div class="item">
          <?php echo $eventprofileStr; ?>
    </div>
        <?php
        echo $form->textArea($model, $eventDescriptionField, array('placeholder' => $eventprofileStr . '...'));
        ?>
</div>
<?php
$this->endWidget();
//echo CHtml::endForm();
?>
<div data-role="controlgroup" data-type="horizontal" style="padding:1px;">
  <button data-role="button"  onclick="javascript:sendIt()">保存</button>   
  <button data-role="button">取消</button>
 </div>
<div data-role="footer" data-position="fixed" data-theme="a" class="ui-footer ui-bar-a ui-footer-fixed slideup ui-fixed-hidden" role="contentinfo">
  <h1 class="ui-title" role="heading" aria-level="1">Copyright billyn.net</h1>
</div>